<?php

namespace app\admin\controller\subject;

use app\common\controller\Backend;

/**
 * 课程章节管理
 *
 * @icon fa fa-circle-o
 */
class Chapter extends Backend
{
    // protected $noNeedRight = ['*'];

    protected $model = null;

    // 设置关联查询
    protected $relationSearch = true;

    public function _initialize()
    {
        parent::_initialize();

        $this->model = model('Subject.Chapter');
        $this->SubjectModel = model('Subject.Subject');


    }

    //章节列表
    public function index($ids = null)
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);

        if ($this->request->isAjax())
        {
            if ($this->request->request('keyField'))
            {
                return $this->selectpage();
            }

            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $AuthWhere = ['subid' => $ids];

            $total = $this->model
                ->with(['subject'])
                ->where($where)
                ->where($AuthWhere)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->count();


            $list = $this->model
                ->with(['subject'])
                ->where($where)
                ->where($AuthWhere)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }

        return $this->view->fetch();
    }


}
